from abc import ABC, abstractclassmethod

from .tensor import Tensor


def get_parameters(obj):
    parameters = []
    if isinstance(obj, Tensor):
        parameters.append(obj)
    elif isinstance(obj, list):
        for x in obj:
            parameters.extend(get_parameters(x))
    elif hasattr(obj, '__dict__'):
        for k, v in obj.__dict__.items():
            parameters.extend(get_parameters(v))
    return parameters


class Model(ABC):
    def __init__(self) -> None:
        super().__init__()

    @abstractclassmethod
    def forward(self, x):
        ...

    def get_params(self):
        return get_parameters(self)
